package kr.or.javacafe.news.repository;

import java.util.List;

import kr.or.javacafe.demo.domain.mongo.TwitterWord;
import kr.or.javacafe.news.domain.GoogleNews;
import kr.or.javacafe.news.domain.NewsWordCount;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

@Repository
public class NewsRepository {

	@Autowired
	MongoTemplate mongoTemplate;
	
	
	public GoogleNews selectGoogleNews(Query query) {
		return mongoTemplate.findOne(query, GoogleNews.class);
	}
	
	public void insertGoogleNews(GoogleNews obj) {
		mongoTemplate.insert(obj);
	}

	public List<GoogleNews> selectGoogleNewsAllList(Query query) {
		return mongoTemplate.find(query, GoogleNews.class);
	}
	
	public long selectGoogleNewsCount() {
		return mongoTemplate.count(new Query(), GoogleNews.class);
	}
	
	public void insertNewsWordCount(NewsWordCount obj) {
		mongoTemplate.insert(obj);
	}

	public long selectWordCountCount() {
		return mongoTemplate.count(new Query(), NewsWordCount.class);
	}
	
	public List<NewsWordCount> selectWordCount(Query query) {
		return mongoTemplate.find(query, NewsWordCount.class);
	}
}
